
package sumo.box;

import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;


public class Personagem {
    private int x = 0;
    private int y = 0;
    private int movs = 0;
    private Image img = null;
    
    public Personagem(int x, int y) throws SlickException {
        this.x = x;
        this.y = y;
        this.img = new Image("src/IMAGES/baixo00.png");
    }
    
    public void setX(int x){
        this.x = x;
    }
    public void setY(int y){
        this.y = y;
    }
    public int getX(){
        return this.x;
    }
    public int getY(){
        return this.y;
    }
    public void addX(int x){
        this.x = this.x + x;
    }
    public void addY(int y){
        this.y = this.y + y;
    }    
    public void addMovs(){
        this.movs++;
    }
    public void subMovs(){
        this.movs--;
    }
    public int getMovs(){
        return this.movs;
    }    
    public void setImg(java.lang.String arq) throws SlickException{
        this.img = new Image("src/IMAGES/"+arq);
    }
    public Image getImg(){
        return this.img;
    }
    
    
    
    
    public void goEsq(Lugar places[], Bomba[] bombs, boolean[][] blocked, int x, int y, int i) throws SlickException{
        if(!BlockedTest.test(blocked, this.x - 40, this.y)){
            if(BombTest.test(bombs, this.x - 40, this.y)){
                Bomba bomba = BombTest.qualBomba(bombs,this.x-40,this.y);
                bomba.goEsq(bombs, places, this, blocked, bomba.getX(), bomba.getY(), i);
            }
            else {
                this.addX(-40);
                this.addMovs();
                Desfazer.setMove("heroEsq");
                Box.passoSound();
            }
        }
        this.setImg("esq0"+(this.movs%3)+".png");
    }
    
    
    
    
    public void goDir(Lugar places[], Bomba[] bombs, boolean[][] blocked, int x, int y, int i) throws SlickException{
       
        
        if(!BlockedTest.test(blocked, this.x + 40, this.y)){
            if(BombTest.test(bombs, this.x + 40, this.y)){
                Bomba bomba = BombTest.qualBomba(bombs,this.x+40,this.y);
                bomba.goDir(bombs, places, this, blocked, bomba.getX(), bomba.getY(), i);
            }

            else {
                this.addX(40);
                this.addMovs();
                Desfazer.setMove("heroDir");
                Box.passoSound();
            }
        }
        
        
        
        this.setImg("dir0"+(this.movs%3)+".png");
    }
    
    
    
    
    public void goCima(Lugar places[], Bomba[] bombs, boolean[][] blocked, int x, int y, int i) throws SlickException{
        //nao tem muro
        if(!BlockedTest.test(blocked, this.x, this.y - 40)){
            //nao tem muro e tem uma bomba
            if(BombTest.test(bombs, this.x, this.y-40)){
                //nao tem um muro depois da bomba -> anda cara e anda bomba
              
                    Bomba bomba = BombTest.qualBomba(bombs,this.x,this.y-40);
                    bomba.goCima(bombs, places, this, blocked, bomba.getX(), bomba.getY(), i);
                
                //tem um muro depois da bomba -> nada
                
            }
            //nao tem muro não tem bomba -> andar
            else {
                this.addY(-40);
                this.addMovs();
                Desfazer.setMove("heroCima");
                Box.passoSound();
            }
        }
        this.setImg("cima0"+(this.movs%3)+".png");
    }
    
    
    
    
    public void goBaixo(Lugar places[], Bomba[] bombs, boolean[][] blocked, int x, int y, int i) throws SlickException{
        if(!BlockedTest.test(blocked, this.x, this.y + 40)){
            if(BombTest.test(bombs, this.x, this.y+40)){
                Bomba bomba = BombTest.qualBomba(bombs,this.x,this.y+40);
                bomba.goBaixo(bombs, places, this, blocked, bomba.getX(), bomba.getY(), i);
            }
            else {
                this.addY(40);
                this.addMovs();
                Desfazer.setMove("heroBaixo");
                Box.passoSound();
            }
        }
        this.setImg("baixo0"+(this.movs%3)+".png");
    }
}
